Improving Type Error Messages in OCaml
نویسنده
چکیده
Cryptic type error messages are a major obstacle to learning OCaml or other ML-based languages. In many cases, error messages cannot be interpreted without a sufficiently-precise model of the type inference algorithm. The problem of improving type error messages in ML has received quite a bit of attention over the past two decades, and many different strategies have been considered. The challenge is not only to produce error messages that are both sufficiently concise and systematically useful to the programmer, but also to handle a full-blown programming language and to cope with large-sized programs efficiently. In this work, we present a modification to the traditional ML type inference algorithm implemented in OCaml that, by significantly reducing the left-to-right bias, allows us to report error messages that are more helpful to the programmer. Our algorithm remains fully predictable and continues to produce fairly concise error messages that always help making some progress towards fixing the code. We implemented our approach as a patch to the OCaml compiler in just a few hundred lines of code. We believe that this patch should benefit not just to beginners, but also to experienced programs developing large-scale OCaml programs.
منابع مشابه
Semantics-Directed Compiler Generation
This dissertation concerns the design and implementation of SemCom, an interpreter generator for arbitrary languages, which compiles a two-level operational semantics (in either bigor small-step style). Input to SemCom is expressed in a purpose-designed Semantic Description Language (SDL). An SDL file contains the definition of an evaluation and typing relation, and can express type systems up ...
متن کاملPractical SMT-Based Type Error Localization Extended Version
Compilers for statically typed functional programming languages are notorious for generating confusing type error messages. When the compiler detects a type error, it typically reports the program location where the type checking failed as the source of the error. Since other error sources are not even considered, the actual root cause is often missed. A more adequate approach is to consider al...
متن کاملOn Practical SMT-Based Type Error Localization
Compilers for statically typed functional programming languages are notorious for generating confusing type error messages. When the compiler detects a type error, it typically reports the program location where the type checking failed as the source of the error. Since other error sources are not even considered, the actual root cause is often missed. A more adequate approach is to consider al...
متن کاملImproving type-error messages in functional languages
Although type systems do detect type errors in programs, they often produce uninformative error messages, that hardly give information about how to repair a program. One important shortcoming is the inability to highlight the most likely cause for the detected inconsistency. This paper presents a type inferencer with improved error reporting facilities, based on the construction of type constra...
متن کاملCatch Me If You Can - Looking for Type-Safe, Hierarchical, Lightweight, Polymorphic and Efficient Error Management in OCaml
This is the year 2008 and ML-style exceptions are everywhere. Most modern languages, whether academic or industrial, feature some variant of this mechanism. Languages such as Java even feature static coverage-checking for such exceptions, something not available for ML languages, at least not without resorting to external tools. In this document, we demonstrate a design principle and a tiny lib...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 2014